package com.andreamerla.petslife.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by IntelliJ IDEA.
 * User: a.merla
 * Date: 19/07/13
 * Time: 11.27
 */
public class ConnectionDetector {
    /**
     * Checking for all possible internet providers
     */
    public static boolean isConnectedToInternet(Context context) {
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null)
                for (NetworkInfo anInfo : info)
                    if (anInfo.getState() == NetworkInfo.State.CONNECTED)
                        return true;

        }
        return false;
    }
}
